package com.telnetnz.ticketdesk.dao.wrapper;

import java.util.List;

import net.sf.ehcache.Cache;

import com.rockbb.common.dao.CacheManagerBean;
import com.telnetnz.ticketdesk.dao.entity.TicketToTagEntity;
import com.telnetnz.ticketdesk.dao.mapper.TicketToTagMapper;

public class TicketToTagWrap {

	public static final String[] ORDER_BY = { 
		"tag_name"
	};
	public static final String[] ORDER = {"DESC", "ASC"};

	private TicketToTagMapper mapper;
	private Cache cache;

	public TicketToTagWrap() {}

	public TicketToTagWrap(
			TicketToTagMapper mapper, 
			CacheManagerBean cacheManagerBean) {
		this.mapper = mapper;
		this.cache = cacheManagerBean.get(mapper.getClass().getName());
	}

	public TicketToTagEntity selectByTicketIdAndTagId(long ticketId, long tagId) {
		TicketToTagEntity entity = new TicketToTagEntity();
		entity.setTicketId(ticketId);
		entity.setTagId(tagId);
		return mapper.selectByTicketIdAndTagId(entity);
	}

	public void insert(long ticketId, long tagId, String tagName)
	{
		TicketToTagEntity entity = new TicketToTagEntity();
		entity.setTicketId(ticketId);
		entity.setTagId(tagId);
		entity.setTagName(tagName);
		mapper.insert(entity);
	}

	public void deleteTicketToTag(long ticketId, long tagId)
	{
		TicketToTagEntity entity = new TicketToTagEntity();
		entity.setTicketId(ticketId);
		entity.setTagId(tagId);
		mapper.delete(entity);
	}

	public void deleteByTicketId(long ticketId)
	{
		mapper.deleteByTicketId(ticketId);
	}

	public void deleteByTagId(long tagId)
	{
		mapper.deleteByTagId(tagId);
	}

	public List<TicketToTagEntity> selectByTagId(long tagId)
	{
		return mapper.selectByTagId(tagId);
	}

	public List<TicketToTagEntity> selectByTicketId(long ticketId)
	{
		return mapper.selectByTicketId(ticketId);
	}

	public Cache getCache() 
	{
		return cache;
	}
}

